package com.lz.base.project.thread.completableFuture;

import com.lz.base.common.utils.http.OkHttpUtil;
import com.lz.base.common.utils.http.SstInf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.CountDownLatch;

public class WeatherLatch {

    private static final Logger logger = LoggerFactory.getLogger(WeatherLatch.class);

    public static String getWeather(String principal, CountDownLatch countDownLatch) throws Exception {
        String s = "";
        try {
            String annualRate = "3";
            String duration = "100";
            String type = "day";
            SstInf sstInf = new SstInf();
            sstInf.setInfFullUrl("https://api.oick.cn/dutang/api.php");
            sstInf.setInfRequest("{principal: " + principal + ",annualRate: " + annualRate + ",duration: " + duration + ",type: " + type + "}");
            s = OkHttpUtil.requestGet(sstInf);
            System.out.println("city:" + s);
            System.out.println("Thread.currentThread().getName():"+Thread.currentThread().getName());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
        }finally {
            countDownLatch.countDown();
        }
        return s;
    }
}